#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
void solve()
{
    ll n;
    cin >> n;
    vector<ll> v(n + 1);
    vector<ll> sum0(32, 0);
    vector<ll> sum1(32, 0);
    for (ll i = 1; i <= n; i++)
    {
        cin >> v[i];
        for (ll j = 0; j <= 30;j++)
        {
            ll now = v[i] >> j & 1;
            if(now==0)
            {
                sum0[j]++;
            }
            else {
                sum1[j]++;
            }
        }
    }
    ll ans = 0, res = 0;
    for (ll i = 1; i <= n;i++)
    {
        ans = 0;
        for (ll j = 0; j <= 30;j++)
        {
            ll now = v[i] >> j & 1;
            if(now==1)
            {
                ans += sum0[j] * pow(2, j);
            }
            else
                ans += sum1[j] * pow(2, j);
        }
        res = max(ans, res);
    }
    cout << res << endl;
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
